package com.tjsinfo.tjsoa.vote.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.vote.bo.ITVoteColumnBO;
import com.tjsinfo.tjsoa.vote.bo.ITVoteConformationBO;
import com.tjsinfo.tjsoa.vote.vo.TVoteColumn;
import com.tjsinfo.tjsoa.vote.vo.TVoteConformation;

public class VoteColumnListAction extends Action {
	private ITVoteColumnBO columnBo;
	private ITVoteConformationBO conformationBo;
	public void setConformationBo(ITVoteConformationBO conformationBo) {
		this.conformationBo = conformationBo;
	}
	public void setColumnBo(ITVoteColumnBO columnBo) {
		this.columnBo = columnBo;
	}	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
            String headId = request.getParameter("headId");
            String parentId = request.getParameter("parentId");
            String conformationId = request.getParameter("conformationId");
			
			List<TVoteColumn> columnLists = columnBo.findBy(headId, parentId);

			//String str = "";
			//for (int i = 0; i < columnLists.size(); i++) {
				//str = str + columnLists.get(i).getName() + "%";
			//}
			
			//if(str.substring(str.length()-1, str.length()).equals("%")){
				//str = str.substring(0, str.length()-1);
			//}

			//response.setContentType("text/html; charset=UTF-8"); 
			//response.getWriter().print(str);
			
			TVoteConformation vc = conformationBo.findById(conformationId);
			request.setAttribute("columnLists", columnLists);
			request.setAttribute("conformation", vc);
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
